package com.admin.controller;


import com.admin.entity.Room;
import com.admin.entity.User;
import com.admin.service.RoomService;
import com.admin.utils.Result;
import com.admin.vo.query.RoomQueryVo;
import com.admin.vo.query.RoomQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

/**
 * <p>
 * 宿舍表 前端控制器
 * </p>
 *
 * @author szy
 * @since 2023-03-14
 */
@RestController
@RequestMapping("/api/room")
public class RoomController {
    @Resource
    private RoomService roomService;

    /*分页查询*/
    @GetMapping("/list")
    public Result list(RoomQueryVo roomQueryVo){
        IPage<Room> page = new Page<Room>(roomQueryVo.getPageNo(), roomQueryVo.getPageSize());
        roomService.getRoomyByPage(page,roomQueryVo);
        return Result.ok(page);
    }

    @PostMapping("/add")
    public Result add(@RequestBody Room room){
        if (roomService.save(room)){
            return Result.ok().message("添加成功");
        }else{
            return Result.error().message("添加失败");
        }
    }

    @PutMapping("/update")
    public Result update(@RequestBody Room room){
        if (roomService.updateById(room)){
            return Result.ok().message("修改成功");
        }else{
            return Result.error().message("修改失败");
        }
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        if (roomService.removeById(id)){
            return Result.ok().message("删除成功");
        }else{
            return Result.error().message("删除失败");
        }
    }
}

